package com.hangzhou.welbeing.welbeinginstrument.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hangzhou.welbeing.welbeinginstrument.R;
import com.hangzhou.welbeing.welbeinginstrument.bean.PostCommentsBean;
import com.hangzhou.welbeing.welbeinginstrument.config.RBConstants;
import com.hangzhou.welbeing.welbeinginstrument.inteface.OnRecyclerViewItemClickListener;
import com.hangzhou.welbeing.welbeinginstrument.tool.GlideCircleTransform;

import java.util.ArrayList;
import java.util.List;

/**
 * 时间 2017 年 09 月 19.
 * 作者 Administrator  刘传华
 * 公司 杭州惟君医疗科技有限公司
 * 包名 com.hangzhou.welbeing.pregnant.welbeing_pregnant.adapter
 * 工程名 welbeing_pregnant
 */
public class SimilarProfilePageFocusedAdapter extends RecyclerView.Adapter<SimilarProfilePageFocusedAdapter.ViewHolder> implements View.OnClickListener{
    private OnRecyclerViewItemClickListener mOnItemClickListener = null;
    private List<PostCommentsBean.DataBean> mlist = new ArrayList<>();
    private  Context mcontext;


    public void addItem(List<PostCommentsBean.DataBean> mlistBean){
        mlist.clear();
        mlist.addAll(mlistBean);
        notifyDataSetChanged();
    }

    public SimilarProfilePageFocusedAdapter(Context context) {
        mcontext = context;
    }

    public void setOnItemClickListener(OnRecyclerViewItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_profile_page_focused_recyclerview,parent,false);
            ViewHolder viewHolder = new ViewHolder(view);
            view.setOnClickListener(this);
            return viewHolder;

    }

    @Override
    public void onBindViewHolder(SimilarProfilePageFocusedAdapter.ViewHolder holder, final int position) {

        holder.tv_name.setText(mlist.get(position).cus_name);
        holder.tv_commentaries.setText(mlist.get(position).content);
        holder.tv_date.setText(mlist.get(position).addtime);
            String count = mlist.get(position).count;
            if(count.equals("0")){
                holder.rl_revert.setVisibility(View.GONE);
                holder.ll_reply.setVisibility(View.GONE);
            }else{
               // holder.rl_revert.setVisibility(View.VISIBLE);
                //holder.tv_revert_number.setText("共"+count+"条回复");
                holder.ll_reply.setVisibility(View.GONE);
            }
        holder.tv_revert.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(mOnItemClickListener != null ){
                        mOnItemClickListener.onItemFirstButtonClick(v,position);
                    }
                }
            });
            //holder.iv_head_portrait
            Glide.with(mcontext).load(RBConstants.SERVER_URL+"/Public/Uploads/"+mlist.get(position).cus_logo).transform(new GlideCircleTransform(mcontext)).into(holder.iv_head_portrait);
        }



    @Override
    public int getItemCount() {
        return mlist.size();
    }

    @Override
    public void onClick(View v) {
        if(mOnItemClickListener != null ){
            mOnItemClickListener.onItemClick(v);
        }
    }
    /**
     * 身体布局Holder
     */
    static class ViewHolder extends RecyclerView.ViewHolder {

        private TextView tv_name;
        private  TextView tv_commentaries;
        private  TextView tv_date;
        private  TextView tv_revert;
        private  TextView tv_Who_reply;
        private  TextView tv_revert_content;
        private  TextView tv_revert_number;
        private LinearLayout rl_revert;
        private ImageView iv_head_portrait;
        private LinearLayout ll_reply;



        public ViewHolder(View itemView) {
            super(itemView);

            tv_name =  (TextView) itemView.findViewById(R.id.item_profile_page_focused_recyclerview_tv_name);
            tv_commentaries =  (TextView) itemView.findViewById(R.id.item_profile_page_focused_recyclerview_tv_commentaries);
            tv_date =  (TextView) itemView.findViewById(R.id.item_profile_page_focused_recyclerview_tv_date);
            tv_revert =  (TextView) itemView.findViewById(R.id.item_profile_page_focused_recyclerview_tv_revert);
            tv_Who_reply =  (TextView) itemView.findViewById(R.id.item_profile_page_focused_recyclerview_tv_Who_reply);
            tv_revert_content =  (TextView) itemView.findViewById(R.id.item_profile_page_focused_recyclerview_tv_revert_content);
            tv_revert_number =  (TextView) itemView.findViewById(R.id.item_profile_page_focused_recyclerview_tv_revert_number);
            rl_revert =  (LinearLayout) itemView.findViewById(R.id.item_profile_page_focused_recyclerview_rl_revert);


            iv_head_portrait =  (ImageView) itemView.findViewById(R.id.item_profile_page_focused_recyclerview_iv_head_portrait);
            ll_reply =  (LinearLayout) itemView.findViewById(R.id.item_profile_page_focused_recyclerview_ll_reply);
        }
    }
}
